package br.com.churrascariabrasadeouro.persistencia;

import java.sql.Connection;
import java.util.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import br.com.churrascariabrasadeouro.Principal;
import br.com.churrascariabrasadeouro.negocio.Comanda;
import br.com.churrascariabrasadeouro.negocio.Item;
import br.com.churrascariabrasadeouro.negocio.Produto;

public class ComandaDAO {

	/*public void insereComanda(Comanda comanda) throws SQLException{
		Connection conexao = Principal.banco.obterConexao();
		PreparedStatement ps = conexao.prepareStatement("insert into comanda (DATA,VALOR) VALUES(?,?)");
		ps.setDate(1, (Date) comanda.getData());
		ps.setDouble(2, comanda.getValor());*/

	public Integer incluirComanda(Comanda comanda){
		try {
			Connection conexao = Principal.banco.obterConexao();
			PreparedStatement ps = conexao.prepareStatement("insert into comanda " +
					"(DATA,OBSERVACAO,VALOR) values (?,?,?)");
			
			ps.setDate(1, new java.sql.Date( new Date().getTime()));
			ps.setString(2, comanda.getObservacao());
			ps.setDouble(3, comanda.getValor ());
			ps.execute();
			conexao.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		for (Item item : comanda.getItens()) {
			
		}
			
		
		
		return null;
		
	}
	
	
	public Integer estornarComanda(Integer id){
		return id;
	}
	
	public List<Comanda> listartodasComanda(){
		List<Comanda> comandas = new ArrayList<Comanda>();
		try {
			Connection conexao = Principal.banco.obterConexao();
			Statement stmt = conexao.createStatement();
			ResultSet rs = stmt.executeQuery("Select ID,DATA,OBSERVACAO, VALOR FROM PRODUTO");
			while(rs.next()){
				Comanda comanda = new Comanda();
				comanda.setId(rs.getInt(1));
				comanda.setData(new Date(rs.getDate(2).getTime()));
				comanda.setObservacao(rs.getString(2));
				comanda.setValor(rs.getDouble(3));
				comandas.add(comanda);
			}
			conexao.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return comandas;
	}


	public void cadastrarComanda(Comanda comanda) {
		// TODO Auto-generated method stub
		
	}
		

}
		
